// in src/App.js
import React from 'react';
import { Admin, Resource,ListGuesser, resolveBrowserLocale } from 'react-admin';
import { UserList, UserCreate } from './users';
import { Dashboard } from './dashboard/index';
import authProvider from './authProvider';
import dataProvider from './dataProvider';
import { PostList, PostEdit, PostCreate } from './posts';
import PostIcon from '@material-ui/icons/Book';
import UserIcon from '@material-ui/icons/Group';
import zhLang from "./i18n/zh";
import enLang from "./i18n/en";
import myTestSage from './onDataChangeSaga';
import { createMuiTheme } from '@material-ui/core/styles';
import indigo from '@material-ui/core/colors/indigo';
import pink from '@material-ui/core/colors/pink';
import red from '@material-ui/core/colors/red';
import { Layout } from './layout';
import Cars from './cars';
const i18nProvider = (locale) => {
  
  if (locale === 'zh') {
      return zhLang;
  }
  // Always fallback on english
  return enLang;
};
const browserLang = resolveBrowserLocale();
const theme = createMuiTheme({
  palette: {
    type: 'dark', // Switching the dark mode on is a single property value change.
  },
});

const myTheme = createMuiTheme({
    palette: {
        primary: indigo,
        secondary: pink,
        error: red,
        contrastThreshold: 3,
        tonalOffset: 0.2,
    },
    typography: {
        // Use the system font instead of the default Roboto font.
        fontFamily: [
            '-apple-system',
            'BlinkMacSystemFont',
            '"Segoe UI"',
            'Arial',
            'sans-serif',
        ].join(','),
    },
    overrides: {
        MuiButton: { // override the styles of all instances of this component
            root: { // Name of the rule
                color: 'white', // Some CSS
            },
        },
    },
});

class App extends React.Component {

  render(){
    return (
      <Admin 
          dashboard={Dashboard} 
          dataProvider={dataProvider} 
          authProvider={authProvider}    
          locale={browserLang} 
          i18nProvider={i18nProvider} 
          customSagas={[ myTestSage ]}
          appLayout={Layout}
        >
          <Resource name="posts" list={PostList}  edit={PostEdit} create={PostCreate}  icon={PostIcon} />
          <Resource name="movies" list={ListGuesser}  />
          <Resource name="cars" {...Cars}  />
          <Resource name="users" list={UserList}  icon={UserIcon}   create={UserCreate}/>
        </Admin>
    )
  }
}

export default App;